<%
# Copyright (C) 2016 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<div class="federated_attributes">
  <h4><%= t 'Federated Attributes' %></h4>
  <p><%= t <<-TEXT
Federated attributes are information sent from your authentication provider that can be used
to automatically update corresponding information for users in Canvas each time they log in.
TEXT
%></p>
  <table class="ic-Table" style="<%= hidden unless aac.federated_attributes.present? %>">
    <thead>
      <th scope="col"><%= t 'Canvas Attribute' %></th>
      <th scope="col"><%= t 'Provider Attribute' %></th>
      <th scope="col" style="<%= hidden unless aac.jit_provisioning? %>" class="provisioning_only_column">
        <%= t 'Provisioning Only' %>
        <a
          class="icon-info"
          tabindex="0"
          data-tooltip='{"tooltipClass":"popover popover-padded", "position":"right"}'
          title= "<%= t <<-TEXT
        If an attribute is marked as provisioning only, then it will only be used when Just in Time
        Provisioning creates a new user, and will not be kept up to date each time the user logs in.
        TEXT
        %>"
          >
          
        </a>
      </th>
      <td scope="col">&nbsp;</td>
    </thead>
    <tbody>
      <% aac.federated_attributes.each do |(canvas_attribute, provider_attribute)| %>
        <tr>
          <th scope="row" class="canvas_attribute"><span class="canvas_attribute_name"><%= canvas_attribute %></span></th>
          <td><label class="ic-Label screenreader-only" for="aacfa_<%= canvas_attribute %>_attribute_<%= presenter.id_suffix(aac) %>"><%= t 'Provider Attribute' %></label>
            <%= presenter.federated_provider_attribute(aac, canvas_attribute, provider_attribute['attribute']) %>
          </td>
          <td class="provisioning_only_column<%= ' federated_attributes_none' unless aac.jit_provisioning? %>">
            <label class="ic-Label screenreader-only" for="aacfa_<%= canvas_attribute %>_provisioning_only_<%= presenter.id_suffix(aac) %>"><%= t 'Provisioning Only' %></label>
            <input type="checkbox" id="aacfa_<%= canvas_attribute %>_provisioning_only_<%= presenter.id_suffix(aac) %>" name="authentication_provider[federated_attributes][<%= canvas_attribute %>][provisioning_only]" <%= 'checked="checked"'.html_safe if provider_attribute['provisioning_only'] %>/>
          </td>
          <td>
            <button type="button" class="Button Button--icon-action remove_federated_attribute"><i class="icon-trash"></i></button>
          </td>
        </tr>
      <% end %>
      <tr style="display: none" class="attribute_template" data-idsuffix="<%= presenter.id_suffix(aac) %>">
        <th scope="row" class="canvas_attribute">
          <span class="canvas_attribute_name"></span>
        </th>
        <td class="provider_attribute_column">
          <label class="ic-Label screenreader-only"><%= t 'Provider Attribute' %></label>
          <%= presenter.federated_provider_attribute(aac) %>
        </td>
        <td class="provisioning_only_column<%= ' federated_attributes_none' unless aac.jit_provisioning? %>">
          <label class="ic-Label screenreader-only"><%= t 'Provisioning Only' %></label>
          <input type="checkbox" />
        </td>
        <td>
          <button type="button" class="Button Button--icon-action remove_federated_attribute"><i class="icon-trash"></i></button>
        </td>
      </tr>
    </tbody>
  </table>
  <% attrs = presenter.available_federated_attributes(aac) %>
  <div class="<%= attrs.empty? ? 'federated_attributes_none' : 'add_attribute' %>">
    <label class="ic-Label screenreader-only" for="aacfa_add_attribute_<%= presenter.id_suffix(aac) %>"><%= t 'Choose attribute to add' %></label>
    <select id="aacfa_add_attribute_<%= presenter.id_suffix(aac) %>" class="ic-Input canvas_attribute federated_attributes_select">
      <% attrs.each do |attr| %>
        <option><%= attr %></option>
      <% end %>
    </select>
    <button class="Button Button--primary addAttribute--Button add_federated_attribute_button">
      <i class="icon-plus"></i>
      
      <span aria-hidden="true"><%= t 'Attribute' %></span>
    </button>
  </div>

  <% if aac.federated_attributes.empty? %>
    <input type='hidden' name='authentication_provider[federated_attributes]' value='' class='no_federated_attributes'>
  <% end %>
</div>
